package stuServlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.StudentDAO;
import dto.StudentDTO;

@SuppressWarnings("serial")
public class doUpdateServlet extends HttpServlet {
	public doUpdateServlet() {
		super();
	}

	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.process(request, response);

	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.process(request, response);

	}
	public void process(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		String id=request.getParameter("stuId");
		String name=request.getParameter("stuName");
		String sex=request.getParameter("stuSex");
		String year=request.getParameter("year");
	    String month=request.getParameter("month");
	    String day=request.getParameter("day");
	    String birth=year+"-"+month+"-"+day;
	    if(""==year){
	    	year=request.getParameter("y");
	    }
	    if(""==month){
	    	month=request.getParameter("m");
	    }
	    if(""==day){
	    	day=request.getParameter("d");
	    }
	    birth=year+"-"+month+"-"+day;
		StudentDTO dto=new StudentDTO(Integer.parseInt(id),name,sex,birth);
		StudentDAO sdto=new StudentDAO();
		sdto.update(dto);
		request.getRequestDispatcher("doShowList").forward(request, response);
	}

	public void init() throws ServletException {
		// Put your code here
	}

}
